package cn.tedu.gateway.controller;

import cn.tedu.gateway.ip.RedisIpListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("/ip")
public class IpListController {
    @Autowired
    RedisIpListService redisIpListService;

    @GetMapping("/blacklist")
    public Set<String> getBlackList(){
        return redisIpListService.getBlackIpList();
    }

    @GetMapping("/whitelist")
    public Set<String> getWhiteList(){
        return redisIpListService.getWhiteIpList();
    }

    @PostMapping("/blacklist/{ip}")
    public void addBlackList(@PathVariable String ip){
        redisIpListService.addBlackIpList(ip);
    }

    @PostMapping("/whitelist/{ip}")
    public void addWhiteList(@PathVariable String ip){
        redisIpListService.addWhiteIpList(ip);
    }

    @DeleteMapping("/blacklist/{ip}")
    public void removeBlackList(@PathVariable String ip){
        redisIpListService.removeBlackIpList(ip);
    }

    @DeleteMapping("/whitelist/{ip}")
    public void removeWhiteList(@PathVariable String ip){
        redisIpListService.removeWhiteIpList(ip);
    }
}
